<?php

namespace register\controller;

require_once ("./register/model/RegisterModel.php");
require_once ("./register/view/RegisterView.php");
require_once ("./register/model/userDAL.php");

class RegisterController {

	private $view;

	private $model;
	
	private $dal;

	public function __construct(\register\view\RegisterView $view) {
		$this -> model = new \register\model\RegisterModel();
		$this -> view = $view;

	}

	public function registerButtonPressed() {

		return $this -> view -> registerButtonPressed();

	}	
	public function backButtonPressed() {
		
		return $this->view -> backButtonPressed();

	}

	public function validateNewUser() {

		if ($this->view->registerButtonPressed()) {
			if ($this -> model -> registerFailed()) {				
				$this->saveUserToDB();

				return TRUE;
			}
		}
			$this->view->setErrorMessage($this->model->setErrorMessage());
			return FALSE;
	}
	
	public function getFormInputUser(){
		
		return $this -> view -> getFormInputUser();
		
	}
	
	public function getFormInputPassWord(){
		
		return $this -> view -> getFormInputPassWord();
		
	}
	public function saveUserToDB(){
		
		$user = $this->getFormInputUser();
		$password = $this->getFormInputPassWord();
		
		$this -> model -> saveNewUserToDB($user, $password);
		
	}
	

}
